import { menuDataDocument } from '@/views/document/MenuDataDocument'
import { menuDataEditor } from '@/views/editor/menuDataEditor'

export default {
  namespaced: true,
  state: {
    menuNav: [],
    permissions: []
  },
  mutations: {
    INIT_MENU_NAV: (state, list) => {
      state.menuNav = list
    },
    INIT_PERMISSION: (state, list) => {
      state.permissions = list
    },
    CLEAN_MENU_NAV: (state) => {
      state.menuNav = []
    },
    CLEAN_PERMISSION: (state) => {
      state.permissions = []
    }
  },
  getters: {
    getAuthMenu (state) {
      return state.menuNav
    },
    getPermission (state) {
      return state.permissions
    }
  },
  actions: {
    init_menu_data ({commit}, data) {
      let menuData = [
        {
          icon: 'el-icon-s-home',
          name: 'dashboard',
          title: '首页',
          children: []
        }
      ]
      // 如果不需要 组件文档 请注销 menuDataDocument
      menuData = menuData.concat(menuDataDocument, menuDataEditor, data['menus'])
      // menuData = menuData.concat(data['menus'])
      commit('INIT_MENU_NAV', menuData)
      commit('INIT_PERMISSION', data['perms'])
    },
    clean_menu_data ({commit}) {
      commit('CLEAN_MENU_NAV')
      commit('CLEAN_PERMISSION')
    }
  }
}
